package com.siyuanren.gcocp.common.util;


import com.github.binarywang.java.emoji.EmojiConverter;
import com.siyuanren.gcocp.common.consts.BaseConsts;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by   guwr
 * Project_name education-api-parent
 * Path         com.siyuanren.gcocp.common.util.EmojiUtil
 * Date         2017/9/19
 * Time         18:57
 * Description
 */
public class EmojiUtil {

    private static EmojiConverter emojiConverter = EmojiConverter.getInstance();

    /**
     * 将emojiStr转为 带有表情的字符
     * @param emojiStr
     * @return
     */
    public static String emojiConverterUnicodeStr(String emojiStr){
        String result = emojiConverter.toUnicode(emojiStr);
        return result;
    }

    /**
     * 带有表情的字符串转换为编码
     * @param str
     * @return
     */
    public static String emojiConverterToAlias(String str){
        String result=emojiConverter.toAlias(str);
        return result;
    }

    public static String filterEmoji(String source) {
        return filterEmoji(source, BaseConsts.EMOJI_DEFAULT);
    }

    /**
     * emoji表情替换
     *
     * @param source  原字符串
     * @param slipStr emoji表情替换成的字符串
     * @return 过滤后的字符串
     */
    public static String filterEmoji(String source, String slipStr) {
        if (StringUtils.isNotBlank(source)) {
            return source.replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", slipStr);
        } else {
            return source;
        }
    }
}
